package org.example.testdemo.interceptor;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Bean
    public LoginBlocking loginBlocking() {
        return new LoginBlocking();
    }

    @Bean
    public PageBlocking pageBlocking() {
        return new PageBlocking();
    }

    @Bean
    public PermissionBlocking permissionBlocking() {
        return new PermissionBlocking();
    }

    /**
     * 添加Web项目的拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginBlocking()).addPathPatterns("/**")
                .excludePathPatterns("/user/logon","/user/logonOut","/page/**","/css/**","/js/**");

        registry.addInterceptor(pageBlocking()).addPathPatterns("/page/**")
                .excludePathPatterns("/page/logonPage");

        registry.addInterceptor(permissionBlocking()).addPathPatterns("/**")
                .excludePathPatterns("/page/**","/css/**","/js/**","/user/logon","/user/logonOut","/project/authorizeProject","/declare/**","/financialYear/**");
    }
}